package cn.wolfcode.car.business.service.impl;


import cn.wolfcode.car.business.domain.Employee;
import cn.wolfcode.car.business.mapper.EmployeeMapper;
import cn.wolfcode.car.business.query.EmployeeQuery;
import cn.wolfcode.car.business.service.IEmployeeService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.util.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper,Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    public TablePageInfo<Employee> query(EmployeeQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>();
        employeeQueryWrapper.like(StringUtils.hasText(qo.getCustomerName()),"name",qo.getCustomerName())
                .like(StringUtils.hasText(qo.getCustomerName()),"email",qo.getCustomerName());
        employeeQueryWrapper.eq(qo.getIsAdmin()!=null,"admin",qo.getIsAdmin());
        employeeQueryWrapper.eq(qo.getDept()!=null,"dept_id",qo.getDept());
        employeeQueryWrapper.eq(qo.getStatus()!=null,"status",qo.getStatus());
        employeeQueryWrapper.ge(qo.getBeginTime()!=null,"hiredate",qo.getBeginTime());
        employeeQueryWrapper.ge(qo.getEndTime()!=null,"hiredate",qo.getEndTime());
        return new TablePageInfo<Employee>(employeeMapper.selectList(employeeQueryWrapper));
    }

    @Override
    public void deleteOne(Long id) {
        employeeMapper.deleteById(id);
    }

}
